package br.com.ecomm.util.jdbc.jdbcImpl;

import java.sql.Connection;
import java.sql.SQLException;

import br.com.ecomm.exception.ConnectionFactoryException;
import br.com.ecomm.util.jdbc.ConnectionJDBCFactory;
import br.com.ecomm.util.jdbc.ConnectionJDBCFactory.TypesConnections;

public class ConnSingle {
	private static ConnSingle connSingle;
	private Connection conn;
	
	public ConnSingle (){
		conn = ConnectionJDBCFactory.getConnection(TypesConnections.MySQL_CONNECTION);
	}
	
	public static void commit(){
		try {
			connSingle.conn.commit();
		} catch (SQLException e) {
			throw new ConnectionFactoryException("Error de commit");
		}
	}
	
	public static Connection getConnection(){
		if(connSingle!=null){
			connSingle = new ConnSingle();
		}
		return connSingle.conn;
	}
	
}
